<template>
  <div>
    <el-dialog title="设置价格" :visible="true" width="324px" :close-on-click-modal="false" :before-close="close">
      <el-form label-width="48px">
        <el-form-item prop="price" size="small" label="价格"><edu-input-number key="price" :value.sync="price" :args="{ min: 0, precision: 2 }" /></el-form-item>
      </el-form>
      <div slot="footer">
        <el-button type="primary" size="small" :disabled="disabled" @click="submit">确认</el-button>
        <el-button size="small" @click="close">关闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import EduInputNumber from '@public/form/input_number.vue';
export default {
  components: {
    EduInputNumber
  },
  props: {
    row: {
      type: Object,
      required: true
    }
  },
  inject: ['reload'],
  data() {
    return {
      price: this.row.price,
      disabled: false
    };
  },
  methods: {
    close() {
      this.$emit('close');
    },
    submit() {
      // 提交到后台保存
      this.disabled = true;
      this.$http.put(
        '/exam/admin/module/' + this.$route.params.id + '/examination/' + this.row.id + '/edit/price',
        { price: this.price },
        response => {
          this.disabled = false;
          this.$emit('close', this.price);
        },
        error => {
          this.$message.error(error.msg);
        },
        false
      );
    }
  }
};
</script>

<style></style>
